package com.office.forum.manage.comments.service.impl;

import java.util.List;

import com.office.common.utils.DateUtils;
import com.office.forum.manage.comments.domain.ForumComments;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.office.forum.manage.comments.mapper.ForumCommentsMapper;
import com.office.forum.manage.comments.service.IForumCommentsService;

import javax.annotation.Resource;

import static com.office.common.utils.SecurityUtils.getUserId;
import static com.office.common.utils.SecurityUtils.getUsername;

/**
 * 论坛评论Service业务层处理
 *
 * @author ruoyi
 * @date 2025-05-17
 */
@Service
public class ForumCommentsServiceImpl implements IForumCommentsService {

    @Resource
    private ForumCommentsMapper forumCommentsMapper;

    /**
     * @param id 用户id
     * @return 该用户的头像
     */
    @Override
    public String getAvatarByUserId(Long id) {
        return forumCommentsMapper.selectAvatarByUserId(id);
    }

    /**
     * 查询论坛评论
     *
     * @param commentId 论坛评论主键
     * @return 论坛评论
     */
    @Override
    public ForumComments selectForumCommentsByCommentId(Long commentId) {
        return forumCommentsMapper.selectForumCommentsByCommentId(commentId);
    }

    /**
     * 查询论坛评论列表
     *
     * @param forumComments 论坛评论
     * @return 论坛评论
     */
    @Override
    public List<ForumComments> selectForumCommentsList(ForumComments forumComments) {
        return forumCommentsMapper.selectForumCommentsList(forumComments);
    }

    /**
     * 新增论坛评论
     *
     * @param forumComments 论坛评论
     * @return 结果
     */
    @Override
    public int insertForumComments(ForumComments forumComments) {
        forumComments.setStatus(0L);
        forumComments.setUserId(getUserId());
        forumComments.setCreatedAt(DateUtils.getNowDate());
        forumComments.setUserName(getUsername());
        return forumCommentsMapper.insertForumComments(forumComments);
    }

    /**
     * 修改论坛评论
     *
     * @param forumComments 论坛评论
     * @return 结果
     */
    @Override
    public int updateForumComments(ForumComments forumComments) {
        return forumCommentsMapper.updateForumComments(forumComments);
    }

    /**
     * 批量删除论坛评论
     *
     * @param commentIds 需要删除的论坛评论主键
     * @return 结果
     */
    @Override
    public int deleteForumCommentsByCommentIds(Long[] commentIds) {
        return forumCommentsMapper.deleteForumCommentsByCommentIds(commentIds);
    }

    /**
     * 删除论坛评论信息
     *
     * @param commentId 论坛评论主键
     * @return 结果
     */
    @Override
    public int deleteForumCommentsByCommentId(Long commentId) {
        return forumCommentsMapper.deleteForumCommentsByCommentId(commentId);
    }

    @Override
    public List<ForumComments> selectForumCommentsByUserId(Long userId) {
        return forumCommentsMapper.selectForumCommentsByUserId(userId);
    }
}
